from PIL import Image
from paddleocr import PaddleOCR, draw_ocr
import numpy as np

ocr = PaddleOCR(use_angle_cls=True, lang="ch")

img_path = '33.jpg'
result = ocr.ocr(img_path, cls=True)
image = Image.open(img_path).convert('RGB')
boxes = [elements[0] for line in result for elements in line]
txts = [elements[1][0] for line in result for elements in line]
scores = [elements[1][1] for line in result for elements in line]

# Check the structure of boxes
for i in range(len(boxes)):
    print(f"Box {i}: {boxes[i]}")

# Draw OCR result
im_show = draw_ocr(image, boxes, txts, scores, font_path='D:\\xcl\\github\\PaddleOCR\\doc\\fonts\\simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result1.jpg')
